package pers.lonestar.framework.utils.support.comparators;

import java.lang.reflect.Field;
import java.util.Comparator;

import pers.lonestar.framework.utils.support.annotations.ExcelColumnProperty;

public class FieldIndexComparator implements Comparator<Field> {
    @Override
    public int compare(Field field1, Field field2) {
        int index1 = Integer.MAX_VALUE, index2 = Integer.MAX_VALUE;
        ExcelColumnProperty fieldProperty1 = field1.getAnnotation(ExcelColumnProperty.class);
        ExcelColumnProperty fieldProperty2 = field2.getAnnotation(ExcelColumnProperty.class);
        if (fieldProperty1 != null) {
            index1 = fieldProperty1.index();
        }
        if (fieldProperty2 != null) {
            index2 = fieldProperty2.index();
        }
        return index1 - index2;
    }
}
